package com.wei.storage.service;

import com.wei.common.entity.Storage;
import com.wei.common.service.StorageService;
import com.wei.storage.dao.StorageMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author weichuanyuan
 * @version 1.0
 * @date 2021/8/29 9:31
 */
@DubboService(interfaceClass = StorageService.class)
@Service
public class StorageServiceImpl implements StorageService {
    @Autowired
    private StorageMapper storageMapper;


    @Override
    public boolean reduceStorage(Storage storage) {
        System.out.println("扣库存");
        Storage s = storageMapper.selectById(storage.getProductId());
        s.setProductNumber(s.getProductNumber().subtract(storage.getProductNumber()));
        return storageMapper.updateById(s) > 0;
    }


    @Override
    public boolean reduceStorageException(Storage storage) {
        System.out.println("扣库存");
        Storage s = storageMapper.selectById(storage.getProductId());
        s.setProductNumber(s.getProductNumber().subtract(storage.getProductNumber()));
        storageMapper.updateById(s);
        int index = 10/0;
        s.setProductNumber(s.getProductNumber().subtract(storage.getProductNumber()));
        return storageMapper.updateById(s) > 0;
    }
}
